<!doctype html>
<html>

  <head>
    <meta charset="UTF-8">
    <title></title>
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link href="../css/mui.min.css" rel="stylesheet" />
    <link rel="stylesheet" href="../css/1px.css" />
    <style>
      html {
        font-family: Roboto, Arial, "Noto Sans CJK SC", "Noto Sans CJK TC", "Pingfang SC", "Microsoft Yahei", "WenQuanYi Micro Hei", sans-serif;
      }
      
      body {
        overflow-x: hidden;
        background-color: #fff !important;
      }
      
      .mui-content {
        font-size: 13px;
        background-color: #fff;
      }
      /**/
      
      .inventory-list {
        width: 90%;
        margin-left: 5%;
        padding: 5px;
        height: 170px;
        margin-top: 10px;
        margin-bottom: 5px;
      }
      
      .complete {
        float: right;
        margin-right: 10px;
      }
      
      .storeName {
        font-weight: 600;
      }
      
      .tips {
        height: 58px;
        background-color: #C7C7CC;
      }
      
      .btn-box {
        text-align: center;
        margin-top: 10px;
      }
      /*无*/
      
      .no {
        text-align: center;
        line-height: 30px;
        margin-top: 40%;
      }
    </style>
  </head>

  <body>
    <div class="mui-content">
      <div class="inventory-all">

      </div>
      <script id='inventory' type="text/html">
        <%if(list.length > 0){%>
        <% for(var i=0; i<list.length;i++){%>
        <div class="inventory-list vux-1px">
          <div class="storeName">盘点
            <%=list[i].subtask.storeName%> <span class="complete">完成度：<%=list[i].subtask.degree%>%</span></div>
          <div>任务编号：
            <%=list[i].inventoryTask.taskId%>
          </div>
          <div>发布人：
            <%=list[i].inventoryTask.relaseName%>
          </div>
          <div>执行时间：
            <%=list[i].inventoryTask.startDate%>至
            <%=list[i].inventoryTask.endDate%>
          </div>
          <div>距离任务结束还剩：
            <%=list[i].inventoryTask.remainingDay%>天</div>
          <div class="tips">
            任务备注：
            <%=list[i].inventoryTask.taskDescription%>
          </div>
        </div>
        <div class="btn-box">
        	<%if(list[i].subtask.subtaskState===1||list[i].subtask.subtaskState===4){%>
          <button type="button" class="mui-btn mui-btn-primary toDeatil" data-type='1' data-id='<%=list[i].subtask.subtaskId%>'>进入盘点</button>
          <%}else{%>
          <button type="button" class="mui-btn mui-btn-warning  toDeatil" data-type='2' data-id='<%=list[i].subtask.subtaskId%>'>待审查</button>
          <%}%>
        </div>
        <%}%>
        <%} else {%>
        <p class="no">暂无盘点任务</p>
        <%}%>
      </script>

    </div>
    <script src="../config.js"></script>
    <script src="../js/mui.min.js"></script>
    <script src="../js/template-native.js"></script>
    <script type="text/javascript">
      (function($, doc) {
        $.init()
        var inventoryTask

        $.plusReady(function() {
          bindEvent()
          receiveParams()
          getInventory()
        })
        // 接受传值
        function receiveParams() {
          var self = plus.webview.currentWebview();
          currentShopObj = self.currentShopObj;
        }
        // 获取数据
        function getInventory() {
          config.ajax({
            url: '/inventory/checkStoreTask',
            type: 'post',
            data: {
              storeId: currentShopObj.storeId
            },
            success: function(res) {
              if(res.result === 1) {
                storeTask = res.storeTask
                setPage()
              } else {
              	storeTask = []
              	setPage()
              }
            }
          })
        }
        window.addEventListener('getList',function(e){
        		getInventory()
        	})
        //渲染
        function setPage() {
          var html = template('inventory', {
            list: storeTask
          })
          $('.inventory-all')[0].innerHTML = html
        }

        function bindEvent() {
        	//
          $('.mui-content').on('tap', '.toDeatil', function(e) {
            var subTaskId = this.getAttribute('data-id')
            var type = this.getAttribute('data-type')
            var titleText = currentShopObj.storeName + '-盘点'
            $.openWindow({
              url: 'invertoryDetails1.html',
              id: 'invertoryDetails',
              styles: {
                top: 0, //新页面顶部位置
                bottom: 0, //新页面底部位置
                titleNView: {
                  titleText: titleText,
                  titleColor: "#FFFFFF",
                  titleSize: "17px",
                  backgroundColor: "#FF6800",
                  autoBackButton: true,
                  buttons: [{
                    float: "right",
                    fontSize: "18px",
                    fontSrc: "_www/fonts/iconfont.ttf", //wap2app内置字体文件
                    text: "\ue602",
                    onclick: function() {
                      var allPage = plus.webview.all()
                      var nowPage = plus.webview.getWebviewById('index')
                      for(var i = 0; i < allPage.length; i++) {
                        if(allPage[i].getURL() !== nowPage.getURL()) {
                          plus.webview.close(allPage[i]);
                        }
                      }
                    }
                  }],
                  splitLine: {
                    color: "#CCCCCC",
                    height: "1px"
                  }
                }
              },
              extras: {
                currentShopObj: currentShopObj,
                subtaskId: subTaskId,
                type:type
              }
            })
          })
        }
      }(mui, document))
    </script>
  </body>

</html>